let toggle = document.querySelector("#toggle");
let nav = document.querySelector("nav");
let header = document.querySelector("header");
let addUser = document.querySelector("#add-user");
let double = document.querySelector("#double");
let show = document.querySelector("#show-millionaire");
let sort = document.querySelector("#sort");
let calculate = document.querySelector("#calculate");
var i = 0;
//导航栏
toggle.addEventListener("click", function () {

        nav.style.transform = "translateX(0%)";
        header.style.transform = "translateX(15%)";

})
//添加
addUser.addEventListener("click", function () {
    if (i < dataInfo.length) {
        let newH = document.createElement("h2");
        newH.innerHTML = `
        <strong>${dataInfo[i].name}</strong>
        <span>${dataInfo[i].money}</span>
        `
        main.appendChild(newH);
        i++;
    }
})
//资金翻倍
double.addEventListener("click", function () {
    // console.log(dataInfo[i].money);
    dataInfo.forEach(function (i) {
        i.money=(i.money * 2);
    });
    console.log(dataInfo);
})
//查询
show.addEventListener("click", function () {
    let newH = document.querySelectorAll("main>h2");
    let newArr = []
    newH.forEach(function (item) {
        newArr.push(item)
    })
    newArr.forEach(function (item) {
        let x=item.children[1].innerText;
        if (x < 1000000) {
            item.remove();
        }else{
            main.appendChild(item)
        }
    })

})
//财富榜
sort.addEventListener("click", function () {
    let newH = document.querySelectorAll("main>h2");
    let newArr = []
    newH.forEach(function (item) {
        newArr.push(item)
    })
    newArr.sort(function (a, b) {
        return (b.children[1].innerText)-(a.children[1].innerText)
    })
    newArr.forEach(function (item) {
        main.appendChild(item)
    })

})
//总额
calculate.addEventListener("click", function () {
    let newH = document.querySelectorAll("main>h2");
    // let newArr = []
    // let sum=0;
    // newH.forEach(function (item) {
    //     newArr.push(item)
    // })
    // newArr.forEach(function (item) {
    //     let x=item.children[1].innerText;
    //     sum+=x;
    //     console.log(sum);
    // })
})